package com.tianji.learning.controller;


import com.tianji.api.dto.leanring.LearningLessonDTO;
import com.tianji.learning.domain.dto.LearningRecordFormDTO;
import com.tianji.learning.service.ILearningLessonService;
import com.tianji.learning.service.ILearningRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学习记录表 前端控制器
 * </p>
 *
 * @author Yandel
 * @since 2025-05-01
 */
@Api(tags = "学习记录相关接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/learning-records")
public class LearningRecordController {

    private final ILearningRecordService iLearningRecordService;

    /**
     * 查询当前用户指定课程的学习记录
     *
     * @param courseId 课程id
     * @return 课表信息、学习记录及进度信息
     */
    @ApiOperation("查询当前用户指定课程的学习记录")
    @GetMapping("/course/{courseId}")
    public LearningLessonDTO queryLearningRecordByCourse(@PathVariable("courseId") Long courseId) {
        return iLearningRecordService.queryLearningRecordByCourse(courseId);
    }

    /**
     * @param dto
     *
     * <dependency>
     *      <groupId>org.hibernate.validator</groupId>
     *      <artifactId>hibernate-validator</artifactId>
     * </dependency>
     *
     * @Validated 表示校验LearningRecordFormDTO中的字段，
     * 如：@NotNull(message = "小节类型不能为空")
     * 则不需要写判断是否为null了
     */
    @ApiOperation("提交学习记录")
    @PostMapping
    public void addLearningRecord(@RequestBody @Validated LearningRecordFormDTO dto) {
        iLearningRecordService.addLearningRecord(dto);
    }
}
